<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
</html>
<script>
    function setSeconds(value) {
        let result = ""
        let second = parseInt(value)
        if (second > 3600 * 24) {
            let day = second / (3600 * 24)
            second = second % (3600 * 24)
            let hour = second / 3600
            result = `${parseInt(day)}天${parseInt(hour)}时`
        } else if (second > 3600) {
            let hour = second / 3600
            let minute = second % 3600 / 60
            result = `${parseInt(hour)}时${parseInt(minute)}分`
        } else if (second > 60) {
            let minute = second / 60
            let sec = second % 60
            result = `${parseInt(minute)}分${parseInt(sec)}秒`
        } else {
            result = `${parseInt(second)}秒`
        }
        return result
    }

    function formatDuring(data) {
        let days = parseInt(data / (60 * 60 * 24));
        let hours = parseInt((data % (60 * 60 * 24)) / (60 * 60));
        let minutes = parseInt((data % (60 * 60)) / 60);
        let seconds = (data % 60) / 1000;
        return days + " 天 " + hours + " 小时 " + minutes + " 分钟 " + seconds + " 秒 ";
    }

    function formatDuration(t) {
        if (t < 60) {
            return `${t}秒`;
        }
        const unitText = ['天', '时' , '分', '秒']
        const unitMap = [86400, 3600, 60, 0];
        let unit = 86400;
        let result = [];
        let i = 0;
        while (t >= unit) {
            console.log(t)
            console.log(i)
            let n = t % unit;
            t /= unit;
            console.log(n)
            console.log(t)
            console.log(i)
            console.log(unitText[i])
            result.unshift(parseInt(n) + unitText[i])
            // if (parseInt(n)) {
            //     result.unshift(parseInt(n) + unitText[i]);
            // }
            i++;
            if (i <= 3) {
                unit = unitMap[i];
            } else {
                break;
            }
        }
        if (parseInt(t)) {
            result.unshift(parseInt(t) + unitText[i]);
        }
        return result;
    }

    console.log(setSeconds(1036800))
    console.log(formatDuring(1036800))
    console.log(formatDuration(1036800))

</script>